//
//  PackageDetailNaviView.m
//  BaseProject
//
//  Created by 王洋 on 2020/8/2.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "PackageDetailNaviView.h"
#import "HMSegmentedControl.h"

@interface PackageDetailNaviView ()

@property (strong, nonatomic) HMSegmentedControl *segmentedControl;

@property (strong, nonatomic) NSMutableArray *cfgTitleArray;

@end

@implementation PackageDetailNaviView


- (void)awakeFromNib {
    [super awakeFromNib];
        
    [self.segBGView addSubview:self.segmentedControl];
    
    [self.segmentedControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.segBGView bringSubviewToFront:self.quanyiIcon];
    self.segBGView.alpha = 0;
    [self.backBtn setImage:[UIImage imageNamed:@"black_fanhui"] forState:UIControlStateNormal];

    [self layoutIfNeeded];
    
    WEAKSELF
    [self.segmentedControl setIndexChangeBlock:^(NSInteger index) {

        if (index == SegmentPackageDetailSelType_Quanyi) {
            weakSelf.quanyiIcon.hidden = YES;
        }
        if (weakSelf.PackageDetailSegBlock) {
            weakSelf.PackageDetailSegBlock(index);
        }
    }];
}

- (void)fillWithSegType:(SegmentPackageDetailSelType)type {
    
    if (type == SegmentPackageDetailSelType_Quanyi) {
        self.quanyiIcon.hidden = YES;
    }
    [self.segmentedControl setSelectedSegmentIndex:type animated:YES];
}

- (void)refreshNaviFavorStatusWith:(BOOL)isCollect {
    self.isCollect = isCollect;
    switch (self.naviViewStatus) {
        case GoodsNaviViewStatusType_clear:{
            if (self.isCollect) {
                [self.favorBtn setImage:[UIImage imageNamed:@"store_guanzhu_sel"] forState:UIControlStateNormal];
            } else {
                [self.favorBtn setImage:[UIImage imageNamed:@"store_guanzhu"] forState:UIControlStateNormal];
            }
        } break;
        case GoodsNaviViewStatusType_white:{
            if (self.isCollect) {
                [self.favorBtn setImage:[UIImage imageNamed:@"store_guanzhu_bsel"] forState:UIControlStateNormal];
            } else {
                [self.favorBtn setImage:[UIImage imageNamed:@"store_guanzhu_b"] forState:UIControlStateNormal];
            }
        } break;
        default:
            break;
    }
}

- (void)fillWithNaviStatus:(GoodsNaviViewStatusType)naviViewStatus isCollect:(BOOL)isCollect alpha:(CGFloat)alpha {
    
    self.isCollect = isCollect;
    self.naviViewStatus = naviViewStatus;
    self.segBGView.alpha = alpha;
    [self.naviBgImageView setImage:[Utilities imageWithColor:[[UIColor whiteColor] colorWithAlphaComponent:alpha]]];
    
    switch (naviViewStatus) {
        case GoodsNaviViewStatusType_clear:{
            
            [self.backBtn setImage:[UIImage imageNamed:@"black_fanhui"] forState:UIControlStateNormal];
            [self.shareBtn setImage:[UIImage imageNamed:@"store_fenxiang"] forState:UIControlStateNormal];
            [self.msgBtn setImage:[UIImage imageNamed:@"store_xiaoxi"] forState:UIControlStateNormal];
            
            self.favorBtn.hidden = NO;

            if (self.isCollect) {
                [self.favorBtn setImage:[UIImage imageNamed:@"store_guanzhu_sel"] forState:UIControlStateNormal];
            } else {
                [self.favorBtn setImage:[UIImage imageNamed:@"store_guanzhu"] forState:UIControlStateNormal];
            }
            
        } break;
        case GoodsNaviViewStatusType_white:{
            
            [self.backBtn setImage:[UIImage imageNamed:@"public_back_black"] forState:UIControlStateNormal];
            [self.shareBtn setImage:[UIImage imageNamed:@"store_fenxiang_b"] forState:UIControlStateNormal];
            [self.msgBtn setImage:[UIImage imageNamed:@"store_xiaoxi_b"] forState:UIControlStateNormal];
            
            self.favorBtn.hidden = YES;
            
//            if (self.isCollect) {
//                [self.favorBtn setImage:[UIImage imageNamed:@"store_guanzhu_bsel"] forState:UIControlStateNormal];
//            } else {
//                [self.favorBtn setImage:[UIImage imageNamed:@"store_guanzhu_b"] forState:UIControlStateNormal];
//            }
        } break;
        default:
            break;
    }
    
}


- (IBAction)backAction:(id)sender {
    if (self.PackageDetailNaviViewBlock) {
        self.PackageDetailNaviViewBlock(PackageDetailNaviViewActionType_back);
    }
}

- (IBAction)collectAction:(id)sender {
    if (self.PackageDetailNaviViewBlock) {
        self.PackageDetailNaviViewBlock(PackageDetailNaviViewActionType_collect);
    }
}

- (IBAction)shareAction:(id)sender {
    if (self.PackageDetailNaviViewBlock) {
        self.PackageDetailNaviViewBlock(PackageDetailNaviViewActionType_share);
    }
}


- (IBAction)imAction:(id)sender {
    if (self.PackageDetailNaviViewBlock) {
        self.PackageDetailNaviViewBlock(PackageDetailNaviViewActionType_im);
    }
}

- (HMSegmentedControl *)segmentedControl {
    
    if (!_segmentedControl) {
        
        _segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:self.cfgTitleArray.mutableCopy];
        _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
        _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
        _segmentedControl.segmentWidthStyle = HMSegmentedControlSegmentWidthStyleFixed;
        
        _segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName:UIColorHex(0x333333), NSFontAttributeName :[UIFont systemFontOfSize:15]};
        _segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:15]};
        _segmentedControl.selectionIndicatorColor = UIColorHex(0xff4242);
        _segmentedControl.backgroundColor = UIColor.clearColor;
        _segmentedControl.selectionIndicatorHeight = 2;
                
    }
    return _segmentedControl;
}


- (NSMutableArray *)cfgTitleArray {
    if (!_cfgTitleArray) {
        _cfgTitleArray = @[@"套餐",@"评价",@"详情",@"权益"].mutableCopy;
    }
    return _cfgTitleArray;
}

@end
